package com.like.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.like.entity.InfoGetReplyResp;
import com.like.hospitalworld.R;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.List;

public class MoreReplyAdapter extends BaseAdapter {

    boolean isExpand = false;
    private List<InfoGetReplyResp.InformationComment> mComments;

    public MoreReplyAdapter(List<InfoGetReplyResp.InformationComment> comments) {
        this.mComments = comments;
    }

    @Override
    public int getCount() {
        if (!isExpand && mComments.size() > 3)
            return 3;
        return mComments.size();
    }

    public void expand() {
        isExpand = true;
        notifyDataSetChanged();
    }

    public void collapse() {
        isExpand = false;
        notifyDataSetChanged();
    }

    @Override
    public InfoGetReplyResp.InformationComment getItem(int position) {
        return mComments.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        InfoGetReplyResp.InformationComment comment = getItem(position);
        ViewHolder vh;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_more_reply, parent, false);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else
            vh = (ViewHolder) convertView.getTag();
        vh.sReplyContent.setText(comment.commentText.trim());
//        vh.sTime.setText(comment.commentTime);
        vh.sUsername.setText(comment.ickname.trim() + "：");
        return convertView;
    }

    public class ViewHolder {

        @ViewInject(R.id.username)
        TextView sUsername;
        @ViewInject(R.id.reply_content)
        TextView sReplyContent;
        @ViewInject(R.id.time)
        TextView sTime;

        public ViewHolder(View convertView) {
            x.view().inject(this, convertView);
        }
    }
}
